package com.tour.modules.web.controller.api;

import com.tour.common.utils.PageUtils;
import com.tour.common.utils.Query;
import com.tour.common.utils.R;
import com.tour.modules.web.entity.TInfoEntity;
import com.tour.modules.web.service.TInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TInfoApi {

    @Autowired
    private TInfoService tInfoService;

    @RequestMapping("/api/info/list")
    @ResponseBody
    public R list(){
        List<TInfoEntity> tInfoList = tInfoService.queryList(new HashMap<String, Object>());
        return R.ok().put("InfoList", tInfoList);
    }

    @RequestMapping("/api/info/getInfoById")
    @ResponseBody
    public R infoEntity(HttpServletRequest request){
        TInfoEntity tInfoEntity=tInfoService.queryObject(Long.parseLong(request.getParameter("id")));
        return R.ok().put("InfoEntity", tInfoEntity);
    }
    @RequestMapping("/api/info/getInfoByCityId")
    @ResponseBody
    public R getInfoByCityId(HttpServletRequest request){
        List<TInfoEntity> tInfoList = tInfoService.queryListByCityId(Long.parseLong(request.getParameter("cityId")));
        return R.ok().put("InfoList", tInfoList);
    }
    @RequestMapping("/api/info/info")
    public String info(HttpServletRequest request){
        TInfoEntity tInfoEntity=tInfoService.queryObject(Long.parseLong(request.getParameter("id")));
        request.getSession().setAttribute("info",tInfoEntity);
        return "redirect:/front/info.jsp";
    }
}
